package tech.aistar.day05;

/**
 * 本类用来演示: 父类
 *
 * @author: success
 * @date: 2022/7/22 9:48 上午
 */
public class Animal {
    //共性的属性
    private String name;

    private int age;

    public Animal(){
        System.out.println("Animal...");
    }

    public Animal(String name, int age) {
        System.out.println("Animal(name,age)...");
        this.name = name;
        this.age = age;
    }

    //定义公共的方法
    protected void sleep(){
        System.out.println(name+"在睡觉~~~");
    }

    //因为每个子类实现的细节是不一样的.所以该方法肯定是要被子类去重写的.
    public void spark(){
        System.out.println("动物在叫!");
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Animal{");
        sb.append("name='").append(name).append('\'');
        sb.append(", age=").append(age);
        sb.append('}');
        return sb.toString();
    }

    public Animal test() throws Exception{
        return null;
    }

    //static - 不允许被重写,没有多态
    public static void testStatic(){
        System.out.println("父类中的static...");
    }
}
